local shengonghuti = fk.CreateSkill {
  name = "lingling__shengonghuti",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable {
  ["lingling__shengonghuti"] = "神功护体",
  [":lingling__shengonghuti"] = "锁定技，当你于回合外受到伤害时，防止此伤害，改为延迟至回合结束时受到等量伤害。" ..
      "若大于1点，你摸两张牌。",
}

shengonghuti:addEffect(fk.DamageInflicted, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(shengonghuti.name) and
        data.skillName ~= shengonghuti.name and player.room.current ~= player
  end,
  on_use = function(self, event, target, player, data)
    player.room:addPlayerMark(player, shengonghuti.name, data.damage)
    data:preventDamage()
  end,
})

shengonghuti:addEffect(fk.TurnEnd, {
  anim_type = "negative",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(shengonghuti.name) and
        player:getMark(shengonghuti.name) > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = player:getMark(shengonghuti.name)
    room:setPlayerMark(player, shengonghuti.name, 0)
    room:damage {
      from = nil,
      to = player,
      damage = n,
      skillName = shengonghuti.name,
    }
  end,
})

shengonghuti:addEffect(fk.Damaged, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(shengonghuti.name) and
        data.damage > 1 and data.skillName == shengonghuti.name
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(2, shengonghuti.name)
  end,
})

return shengonghuti
